<template>
  <view>
    <view @click="show = true">
      <up-search
        v-model="deprops.query.processName"
        placeholder="请选择工序名称"
        :clearabled="true"
        :showAction="false"
        disabled
      />
    </view>

    <up-picker
      :show="show"
      :columns="compickerlists"
      @confirm="confirm"
      @cancel="show = false"
    ></up-picker>
  </view>
</template>

<script setup>
import { processProcessDictionary } from "../../pages/AdditionalProcess/api.js";
const deprops = defineProps(["query", "title"]);
const Emits = defineEmits("fathersFn");
const show = ref(false);
const gongxuList = ref([]);
const compickerlists = ref([]);
const confirm = (e) => {
  deprops.query.processName = e.value[0];
  console.log(e, "e");
  const obj = gongxuList.value.find(
    (item) => item.processName == deprops.query.processName
  );
  deprops.query.processCode = obj ? obj.processCode : "";
  if (deprops.title == "剪线分卷") {
    deprops.query.processBelong = obj ? obj.processId : "";
    Emits("fathersFn");
  }
  show.value = false;
};
const process_ProcessDictionary = async () => {
  try {
    const res = await processProcessDictionary();
    if (res.code == 1) {
      gongxuList.value = res.data.content;
    } else {
      gongxuList.value = [];
    }
  } catch (err) {
    gongxuList.value = [];
  }
};
onMounted(async () => {
  await process_ProcessDictionary();
  compickerlists.value = [gongxuList.value.map((item) => item.processName)];
  if (deprops.title == "剪线分卷") {
    const obj = gongxuList.value[0];
    deprops.query.processName = obj ? obj.processName : "";
    deprops.query.processBelong = obj ? obj.processId : "";
    Emits("fathersFn");
  }
});
</script>

<style lang="sass" scoped>
</style>